function checkTreeEnd(id){
	
	var ids = id.split('-');
	var finish=true;
	for(var i=1;i<ids.length;i++){

		if(!document.getElementById('noQuestioncChkbox'+ids[i]).checked){
			finish=false;
		}
		if(!document.getElementById('yesQuestioncChkbox'+ids[i]).checked){
			finish=false;
		}

	}
	if(finish){
		document.getElementById('submit').value="Finish";
		document.getElementById('submitAll').action="finish-create.php";
		
	}else{
		document.getElementById('submit').value="Next";
		document.getElementById('submitAll').action="create2.php";
	}


}


function validate_addcategory(){

	if(document.getElementById('categoryName').value=="" || document.getElementById('categoryDescription').value=="" 
			|| document.getElementById('categoryPosition').value=="" || document.getElementById('categoryUrl').value==""){
			document.getElementById('addError').innerHTML="Please complete all fields.";
			return false;
	}
	if(isNaN(document.getElementById('categoryPosition').value)){

			document.getElementById('addError').innerHTML="Please enter valid position.";
			return false;
	}
	
	if(document.getElementById('categoryUrl').value.indexOf(' ')>-1){
			document.getElementById('addError').innerHTML="Please enter valid URL";
			return false;
	}
}
function validate_editcategory(){

		if(document.getElementById('categoryName22').value=="" || document.getElementById('categoryDescription22').value=="" 
			|| document.getElementById('categoryPosition22').value=="" || document.getElementById('categoryUrl22').value==""){
			document.getElementById('editError').innerHTML="Please complete all fields.";
			return false;
	}
	if(isNaN(document.getElementById('categoryPosition22').value)){

			document.getElementById('editError').innerHTML="Please enter valid position.";
			return false;
	}

	if(document.getElementById('categoryUrl22').value.indexOf(' ')>-1){
			document.getElementById('editError').innerHTML="Please enter valid URL";
			return false;
	}


}



function validateCreate(){

	document.getElementById('createError').innerHTML="";
	document.getElementById('txt_focus').style.display='block';
	document.getElementById('txt_focus').focus();
	document.getElementById('txt_focus').style.display='none';



	if(document.getElementById('questionTitle').value==""){
		document.getElementById('createError').innerHTML="Please enter valid title.";
		return false;
	}

 	if(document.getElementById('category').selectedIndex==0 ){
		document.getElementById('createError').innerHTML="Please select a category.";
		return false;
	}
	document.getElementById('url').value=document.getElementById('url').value.toLowerCase();
	if(document.getElementById('url').value=="" ){
		document.getElementById('createError').innerHTML="Please enter valid url.";
		return false;
	}

	if((document.getElementById('initialQuestion').value=="") || (document.getElementById('yesQuestioncChkbox').checked==false &&  document.getElementById('yesQuestion').value=="")||
		(document.getElementById('yesQuestioncChkbox').checked==true && document.getElementById('yesDiagnosis').value=="")||
			(document.getElementById('noQuestioncChkbox').checked==false && document.getElementById('noQuestion').value=="")||
				(document.getElementById('noQuestioncChkbox').checked==true && document.getElementById('noDiagnosis').value=="")){


		document.getElementById('createError').innerHTML="Please fill details for all questions.";
		return false;
	}
	document.getElementById('noQuestionUrl').value=document.getElementById('noQuestionUrl').value.toLowerCase();
	if(document.getElementById('noQuestionUrl').parentNode.parentNode.style.display == ''){
		if(!validateURL(document.getElementById('noQuestionUrl')) ){
			document.getElementById('noQuestionUrl').focus();
			document.getElementById('createError').innerHTML="Space and special characters not allowed in URL.";
			return false;
		}
		else if(document.getElementById('noQuestionUrl').value=="" ){
			document.getElementById('noQuestionUrl').focus();
			document.getElementById('createError').innerHTML="Please complete all fields.";
			return false;
		}
	} 
	document.getElementById('yesQuestionUrl').value=document.getElementById('yesQuestionUrl').value.toLowerCase();
	if(document.getElementById('yesQuestionUrl').parentNode.parentNode.style.display == ''){
		if(!validateURL(document.getElementById('yesQuestionUrl')) ){
			document.getElementById('yesQuestionUrl').focus();
			document.getElementById('createError').innerHTML="Space and special characters not allowed in URL.";
			return false;				
		}
		else if(document.getElementById('yesQuestionUrl').value==""){
			document.getElementById('yesQuestionUrl').focus();
			document.getElementById('createError').innerHTML="Please complete all fields.";
			return false;
		}
	}
			
}

function validateURL(elet){

var checkOK = "abcdefghijklmnopqrstuvwxyz0123456789-";
var checkStr = elet.value;
checkStr = checkStr.toLowerCase();
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}


return allValid;

}


	
	
	function validateCreate2(){

	
	var ids = document.getElementById('allIds').value.split('-');

	for(var i=1;i<ids.length;i++){

		if(document.getElementById('yesQuestion'+ids[i]).value=="" && !document.getElementById('yesQuestion'+ids[i]).disabled){
			document.getElementById('yesQuestion'+ids[i]).focus();
			document.getElementById('create2Error'+ids[i]).innerHTML="Please complete all fields.";
			return false;
		}
		
		if(document.getElementById('noQuestion'+ids[i]).value=="" && !document.getElementById('noQuestion'+ids[i]).disabled){
			document.getElementById('noQuestion'+ids[i]).focus();
			document.getElementById('create2Error'+ids[i]).innerHTML="Please complete all fields.";
			return false;
		}
		if(document.getElementById('yesDiagnosis'+ids[i]).value=="" && !document.getElementById('yesDiagnosis'+ids[i]).disabled){
			document.getElementById('yesDiagnosis'+ids[i]).focus();
			document.getElementById('create2Error'+ids[i]).innerHTML="Please complete all fields.";
			return false;
		}
		if(document.getElementById('noDiagnosis'+ids[i]).value=="" && !document.getElementById('noDiagnosis'+ids[i]).disabled){
			document.getElementById('noDiagnosis'+ids[i]).focus();
			document.getElementById('create2Error'+ids[i]).innerHTML="Please complete all fields.";
			return false;
		}
		document.getElementById('noQuestionUrl'+ids[i]).value=document.getElementById('noQuestionUrl'+ids[i]).value.toLowerCase();
		if(document.getElementById('noQuestionUrl'+ids[i]).parentNode.parentNode.style.display == ''){
			
			if(!validateURL(document.getElementById('noQuestionUrl'+ids[i])) ){
				document.getElementById('noQuestionUrl'+ids[i]).focus();
				document.getElementById('create2Error'+ids[i]).innerHTML="Space and special characters not allowed in URL.";
				return false;				
			}
			else if(document.getElementById('noQuestionUrl'+ids[i]).value==""){
				document.getElementById('noQuestionUrl'+ids[i]).focus();
				document.getElementById('create2Error'+ids[i]).innerHTML="Please complete all fields.";
				return false;

			}
		} 
		document.getElementById('yesQuestionUrl'+ids[i]).value=document.getElementById('yesQuestionUrl'+ids[i]).value.toLowerCase();		
		if(document.getElementById('yesQuestionUrl'+ids[i]).parentNode.parentNode.style.display == ''){
			
			if(!validateURL(document.getElementById('yesQuestionUrl'+ids[i])) ){
				document.getElementById('yesQuestionUrl'+ids[i]).focus();
				document.getElementById('create2Error'+ids[i]).innerHTML="Space and special characters not allowed in URL.";
				return false;				
			}
			else if(document.getElementById('yesQuestionUrl'+ids[i]).value==""){
				document.getElementById('yesQuestionUrl'+ids[i]).focus();
				document.getElementById('create2Error'+ids[i]).innerHTML="Please complete all fields.";
				return false;
			}
		}			
	}
}



function allowEditPage(){


	var ids = document.getElementById('allIds').value.split('-');

	for(var i=1;i<ids.length;i++){
		allowEditAll(ids[i]);
	}
	

}
